import java.util.Random;

public abstract class Actor extends Element {

	private int life;
	private int force;
	private Weapon weapon;

	public Actor() {
		super();
	}

	public int getLife() {
		return life;
	}

	public void setLife(int life) {
		this.life = life;
	}

	public int getForce() {
		return force;
	}

	public void setForce(int force) {
		this.force = force;
	}

	public Weapon getWeapon() {
		return weapon;
	}

	public void setWeapon(Weapon weapon) {
		this.weapon = weapon;
	}

	public void getPotion() {
	}

	public void combattimento(Actor b) {
		while ((this.getLife() > 0) && (b.getLife() > 0)) {
			attacco(this, b);
			if (b.getLife() > 0) {
				attacco(b, this);
			}
			this.visualizzaStat();
			b.visualizzaStat();
		}
		System.out.println("Fine Battaglia!");
	}

	public void attacco(Actor a, Actor b) {
		Random r = new Random();
		double x = r.nextDouble();
		if (x > a.getWeapon().probabilita) {
			b.life = b.life - ((a.getWeapon().danno) + a.force);
			System.out.println("Attacco riuscito!");
		} else
			System.out.println("Attacco fallito!");
	}

	public boolean moveUp(int x, int y) {
		if ((x - 1) == -1) {
			return false;
		} else if (Prison.getEl(x - 1, y) instanceof Potion) {
			getPotion();
			Prison.setEl(x - 1, y, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x - 1, y, this);
			Prison.setEl(x, y, new Empty());
			return true;
		}
	}

	public boolean moveDown(int x, int y) {
		if ((x + 1) == Prison.getROWS()) {
			return false;
		} else if (Prison.getEl(x + 1, y) instanceof Potion) {
			getPotion();
			Prison.setEl(x + 1, y, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x + 1, y, this);
			Prison.setEl(x, y, new Empty());
			;
			return true;
		}
	}

	public boolean moveLeft(int x, int y) {
		if ((y - 1) == -1) {
			return false;
		} else if (Prison.getEl(x, y - 1) instanceof Potion) {
			getPotion();
			Prison.setEl(x, y - 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x, y - 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		}
	}

	public boolean moveRight(int x, int y) {
		if ((y + 1) == Prison.getCOLUMN()) {
			return false;
		} else if (Prison.getEl(x, y + 1) instanceof Potion) {
			getPotion();
			Prison.setEl(x, y + 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x, y + 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		}
	}

	public boolean upLeft(int x, int y) {
		if (((y - 1) == -1) || ((x - 1) == -1)) {
			return false;
		} else if (Prison.getEl(x - 1, y - 1) instanceof Potion) {
			getPotion();
			Prison.setEl(x - 1, y - 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x - 1, y - 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		}
	}

	public boolean upRight(int x, int y) {
		if (((y + 1) == Prison.getCOLUMN()) || ((x - 1) == -1)) {
			return false;
		} else if (Prison.getEl(x - 1, y + 1) instanceof Potion) {
			getPotion();
			Prison.setEl(x - 1, y + 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x - 1, y + 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		}
	}

	public boolean downLeft(int x, int y) {
		if (((y - 1) == -1) || ((x + 1) == Prison.getROWS())) {
			return false;
		} else if (Prison.getEl(x + 1, y - 1) instanceof Potion) {
			getPotion();
			Prison.setEl(x + 1, y - 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x + 1, y - 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		}
	}

	public boolean downRight(int x, int y) {
		if (((y + 1) == Prison.getCOLUMN())
				|| ((x + 1) == Prison.getROWS())) {
			return false;
		} else if (Prison.getEl(x + 1, y + 1) instanceof Potion) {
			getPotion();
			Prison.setEl(x + 1, y + 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		} else {
			Prison.setEl(x + 1, y + 1, this);
			Prison.setEl(x, y, new Empty());
			return true;
		}
	}

	public void visualizzaStat() {
		System.out.println("Life: " + this.getLife());
		System.out.println("Force: " + this.getForce());
		System.out.println("Weapon: " + this.getWeapon().tipo);
	}

}
